//
//  BaseRegisterModel.m
//  Masonry
//
//  Created by Sings on 2019/7/15.
//

#import "BaseRegisterModel.h"
#import "BZModule.h"


@interface BaseRegisterModel ()

@property (nonatomic, strong, readwrite) UIWindow *window;

/// tableViewCell映射对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicTableCellRouting;
/// collectCell映射对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicCollectCellRouting;
/// tableViewHeaderFooter映射对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicTableHeaderFooterRouting;
/// collectionHeader映射对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicCollectionHeaderFooterRouting;
/// viewController路由对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicViewControllerRouting;
/// view路由对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicViewRouting;
/// button路由对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicButtonRouting;
/// 重复控制器删除 不需要删除对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicNoDeleteControllerRouting;
// protocol对应的数组
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicProtocolRouting;
/// 颜色对照表
@property (nonatomic, strong, readwrite) NSMutableDictionary *mdicThemeColorRouting;
/// 主题图片保存路径
@property (nonatomic, copy, readwrite) NSString *strThemeFilePath;

@end

@implementation BaseRegisterModel

static BaseRegisterModel *_baseRegisterManager = nil;


- (NSMutableDictionary *) mdicTableCellRouting {
    if (_mdicTableCellRouting == nil) {
        _mdicTableCellRouting = [NSMutableDictionary dictionary];
    }
    return _mdicTableCellRouting;
}

- (NSMutableDictionary *) mdicCollectCellRouting {
    if (_mdicCollectCellRouting == nil) {
        
        _mdicCollectCellRouting = [NSMutableDictionary dictionary];
    }
    return _mdicCollectCellRouting;
}

- (NSMutableDictionary *) mdicTableHeaderFooterRouting {
    if (_mdicTableHeaderFooterRouting == nil) {
        
        _mdicTableHeaderFooterRouting = [NSMutableDictionary dictionary];
    }
    return _mdicTableHeaderFooterRouting;
}

- (NSMutableDictionary *) mdicViewControllerRouting {
    if (_mdicViewControllerRouting == nil) {
        
        _mdicViewControllerRouting = [NSMutableDictionary dictionary];
    }
    return _mdicViewControllerRouting;
}

- (NSMutableDictionary *) mdicViewRouting {
    if (_mdicViewRouting == nil) {
        
        _mdicViewRouting = [NSMutableDictionary dictionary];
    }
    return _mdicViewRouting;
}
- (NSMutableDictionary *) mdicButtonRouting {
    if (_mdicButtonRouting == nil) {
        _mdicButtonRouting = [NSMutableDictionary dictionary];
    }
    return _mdicButtonRouting;
}

- (NSMutableDictionary *) mdicNoDeleteControllerRouting {
    if (_mdicNoDeleteControllerRouting == nil) {
        
        _mdicNoDeleteControllerRouting = [NSMutableDictionary dictionary];
    }
    return _mdicNoDeleteControllerRouting;
}

- (NSMutableDictionary *) mdicProtocolRouting {
    if (_mdicProtocolRouting == nil) {
        
        _mdicProtocolRouting = [NSMutableDictionary dictionary];
    }
    return _mdicProtocolRouting;
}

- (NSMutableDictionary *) mdicCollectionHeaderFooterRouting {
    if (_mdicCollectionHeaderFooterRouting == nil) {
        _mdicCollectionHeaderFooterRouting = [NSMutableDictionary dictionary];
    }
    return _mdicCollectionHeaderFooterRouting;
}

- (NSMutableDictionary *) mdicThemeColorRouting {
    if (_mdicThemeColorRouting == nil) {
        _mdicThemeColorRouting = [NSMutableDictionary dictionary];
    }
    return _mdicThemeColorRouting;
}

- (NSString *) strThemeFilePath {
    if (_strThemeFilePath == nil) {
        _strThemeFilePath = @"";
    }
    return _strThemeFilePath;
}

+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _baseRegisterManager = [[super allocWithZone:NULL] init];
    });
    
    return _baseRegisterManager;
}

+ (instancetype) allocWithZone:(struct _NSZone *)zone {
    return [BaseRegisterModel sharedInstance];
}

- (id)copyWithZone:(NSZone *)zone {
    return _baseRegisterManager;
}

- (id)mutableCopy {
    return _baseRegisterManager;
}

- (void) registerWindow:(UIWindow *) window {
    self.window = window;
}

- (void) registerTableCellRouting:(NSMutableDictionary *) mdicTableCellRouting {
    [self.mdicTableCellRouting addEntriesFromDictionary:mdicTableCellRouting];
}

- (void) registerCollectCellRouting:(NSMutableDictionary *) mdicCollectCellRouting {
    [self.mdicCollectCellRouting addEntriesFromDictionary:mdicCollectCellRouting];
}

- (void) registerTableHeaderFooterRouting:(NSMutableDictionary *) mdicTableHeaderFooterRouting {
    [self.mdicTableHeaderFooterRouting addEntriesFromDictionary:mdicTableHeaderFooterRouting];
}

- (void) registerCollectionHeaderFooterRouting:(NSMutableDictionary *) mdicCollectionHeaderFooterRouting {
    [self.mdicCollectionHeaderFooterRouting addEntriesFromDictionary:mdicCollectionHeaderFooterRouting];
}

- (void) registerViewControllerRouting:(NSMutableDictionary *) mdicViewControllerRouting {
    [self.mdicViewControllerRouting addEntriesFromDictionary:mdicViewControllerRouting];
}

- (void) registerViewRouting:(NSMutableDictionary *)mdicViewRouting {
    [self.mdicViewRouting addEntriesFromDictionary:mdicViewRouting];
}

- (void) registerButtonRouting:(NSMutableDictionary *) mdicButtonRouting {
    [self.mdicButtonRouting addEntriesFromDictionary:mdicButtonRouting];
}

- (void) registerNoDeleteControllerRouting:(NSMutableDictionary *) mdicNoDeleteControllerRouting {
    [self.mdicNoDeleteControllerRouting addEntriesFromDictionary:mdicNoDeleteControllerRouting];
}

- (void) registerThemeColorRouting:(NSMutableDictionary *) mdicThemeColorRouting {
    [self.mdicThemeColorRouting addEntriesFromDictionary:mdicThemeColorRouting];
}

- (void) registerThemeFilePath:(NSString *) filePath {
    self.strThemeFilePath = filePath;
}

- (void) registerObject:(id) object ToProtocol:(Protocol*) protocol {
    NSString *key = NSStringFromProtocol(protocol);
    if (self.mdicProtocolRouting[key] == nil) {
        self.mdicProtocolRouting[key] = [NSMutableArray array];
    }
    NSMutableArray *array = self.mdicProtocolRouting[key];
    NSString *named = [NSString stringWithFormat:@"%@-%lu",key,(unsigned long)array.count];
    [array addObject:named];
    [[BZModule sharedInstance] bind:object toProtocol:protocol named:named];
    [JSObjection setDefaultInjector:[JSObjection createInjector:[BZModule sharedInstance]]];
}
@end
